﻿using IterationLife.Extensions.Helpers;
using IterationLife.Extensions.Qiniu;
using IterationLife.System.Models;
using Util.Maps;

namespace IterationLife.PlatformBackEnd.AppServices.Dtos.Systems
{
    /// <summary>
    /// 附件数据传输对象扩展
    /// </summary>
    public static class AttachmentDtoExtension
    {
        /// <summary>
        /// 转换为附件数据传输对象
        /// </summary>
        /// <param name="entity">附件实体</param>
        public static AttachmentDto ToDto(this Attachment entity)
        {
            if (entity == null)
                return new AttachmentDto();
            var dto = entity.MapTo(new AttachmentDto());
            dto.Address = QiNiu.DomainName + entity.Address;
            dto.SizeText = FileHelper.CountSize(entity.Size);
            return dto;
        }
    }
}
